package com.guichun.oop.base;

import java.util.Objects;

/**
 * @author guichun
 * @version 1.0.0
 * @ClassName Person.java
 * @email onebigbai@icloud.com
 * @Description 继承-父类
 *
 *   protected 把字段和方法的访问权限控制在继承树内部
 *
 *
 * @createTime 2021-03-01
 */
public class Person {
    public String name;
    public int age;

    public static int number1;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String test(){
        return "test";
    }

    public void run() {
        try {
            Integer.parseInt(null);
        }catch (NumberFormatException e) {
            System.out.println("e = " + e);
        }
        System.out.println("这是Person的Run()方法");
    }

    //重写equals和hashCode防止HashMap冲突还有返回null的问题
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    //    @Override
//    public String toString() {
//        return "Person{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                '}';
//    }
}
